import { action, runInAction } from "mobx";
import { ProjectStore } from "./ProjectStore";

export default class Project {

    private _store: ProjectStore

    constructor(stores: any) {
        const { project } = stores
        this._store = project
    }

    /**
     * 获取我所有的项目
     */
    @action async fetchMe(force: boolean = false) {
        if (!force && this._store.isInited) {
            return
        }

        this._store.isLoading = true
        return $api.invokeApi<IProjectList[]>('/project/project@getProjectData', {})
            .then(res => {
                runInAction(() => {
                    this._store.projects = res.data
                })

            })
            .finally(() => {
                runInAction(() => {
                    this._store.isLoading = false
                })
            })
    }
}